package bam;

public class CreditAccount extends Account {
     private double ceiling;

    public CreditAccount() {
		super();
	}

	public CreditAccount(int id, String password, String name,String personId, String email, double balance,double x) {
		super(id, password, name, personId, email, balance);
		this.ceiling=x;
	}


    public void withdraw(double a) throws OverdraftLimitExceededException{
        double sum=this.getBalance()+ceiling;
        if(sum<a)
         throw(new OverdraftLimitExceededException());
        this.setBalance(0>this.getBalance()-a?0:this.getBalance()-a);
        this.ceiling=this.ceiling>sum-a?sum-a:this.ceiling;
    }

    public double getCeiling() {
        return ceiling;
    }

    public void setCeiling(double ceiling) {
        this.ceiling = ceiling;
    }

    @Override
    public String toString() {
        return "CheckingAccount: Current balance is " +this.getBalance()+ " OverdraftProtection=" + this.getCeiling();
    }


     public  boolean equals(Account x){
	    if(x != null && x instanceof CreditAccount){
	        return true;
	    }
	    return false;
	}
}
